use tempdb 
go

declare @A table(ID int,Sname nvarchar(10))
declare @B table(ID int,Tname nvarchar(10))
insert into @A 
select 1,'zhangfei' 
union all 
select 2,'guanyu' 
union all 
select 3,'liubei' 

select * from @A

insert into @B 
select 1,'zhangsan' 
union all
select 3,'lisi'
union all
select 5,'wangwu' 

select * from @B 

select a.ID,a.Sname,b.ID,b.Tname 
from @A a,@B b
where a.ID=b.ID

select a.ID,a.Sname,b.ID,b.Tname 
from @A a inner join @B b
on a.ID=b.ID

select a.ID,a.Sname,b.ID,b.Tname 
from @A a left join @B b
on a.ID=b.ID

select a.ID,a.Sname,b.ID,b.Tname 
from @A a right join @B b
on a.ID=b.ID




------------------------------------------------------


declare @C table(ID int,Tname nvarchar(10))
insert into @C
select 1,'zhangfei' 
union all 
select 2,'guanyu' 
union all
select 3,'liubei' 
union all
select 3,'liubei'

select * from @C



declare @D table(ID int,Tname nvarchar(10))
insert into @D
select 1,'zhangfei' 
union 
select 2,'guanyu' 
union 
select 3,'liubei' 
union 
select 3,'liubei'

select * from @D